package cn.edu.nwsuaf.teachercenter.service.impl;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import cn.edu.nwsuaf.teachercenter.pojo.Teacher;
import cn.edu.nwsuaf.teachercenter.service.LoginService;

@Service(value="loginService")
public class LoginServiceImpl extends BaseServiceImpl<Teacher> implements LoginService {

	@Override
	public String login(String teacherNo, String teacherPassword, ModelMap modelMap, HttpSession session) {
		// TODO Auto-generated method stub
		Teacher teacher = super.getById(Teacher.class, teacherNo);
		String page = "";
		if(teacher==null){
			modelMap.addAttribute("msg", "用户名不存在");
			page = "redirect:login.html";
		}else{
			if(teacherPassword.equals(teacher.getTeacherPassword())==false){
				modelMap.addAttribute("msg","密码错误");
				page = "redirect:login.html";
			}else{
				session.setAttribute("user", teacher);
				page = "redirect:index.html";
			}
		}
		return page;
	}

	@Override
	public String logout(HttpSession session) {
		// TODO Auto-generated method stub
		session.removeAttribute("user");
		return "redirect:login.html";
	}

}
